package cu.tedu._07springaop.egaop2;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class CartAspect {
//
//    @Before(value = "execution(public boolean cu.tedu._07springaop.egaop2.CartServiceImpl.*(..))")
//    public void before(JoinPoint joinPoint) {
//
//        System.out.println("开始添加购物车");
//    }
//
//    @After(value = "execution(public boolean cu.tedu._07springaop.egaop2.CartServiceImpl.*(..))")
//    public void after(JoinPoint joinPoint) {
//
//        System.out.println("操作完成");
//    }
//
//    @AfterReturning(value = "execution(public boolean cu.tedu._07springaop.egaop2.CartServiceImpl.*(..))", returning = "result")
//    public void afterMethod(JoinPoint joinPoint, boolean result) {
//        if (result) {
//            System.out.println("添加购物车成功");
//        } else {
//            System.out.println("添加购物车失败");
//        }
//    }
@Around(value = "execution(public boolean cu.tedu._07springaop.egaop2.CartServiceImpl.*(..))")
public boolean aroundAddCart(ProceedingJoinPoint joinPoint){
    boolean result = true;
    try {
        System.out.println("开始添加购物车");
        result = (boolean) joinPoint.proceed();
        if (result){
            System.out.println("添加购物车成功");
        } else {
            System.out.println("添加购物车失败");
        }
    } catch (Throwable throwable) {
        throwable.printStackTrace();
    } finally {
        System.out.println("操作完成");
    }

    return result;
}
}
